//
//  HomeViewController.m
//  喜马拉雅首页
//
//  Created by dllo on 15/12/21.
//  Copyright © 2015年 刘倩男. All rights reserved.
//

#import "HomeViewController.h"
#import "HomeTableViewCell.h"
#import "HomeABTableViewCell.h"
#import "HomeCTableViewCell.h"

@interface HomeViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) UITableView *myTableView;
@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"发现";
    UIImage *image = [UIImage imageNamed:@"icon_search_n@2x.png"];
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(searchButtonAction:)];
    
    self.myTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.myTableView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.myTableView];
    
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    

    [self.myTableView registerClass:[HomeTableViewCell class] forCellReuseIdentifier:@"cellCollect"];
    
    [self.myTableView registerClass:[HomeABTableViewCell class] forCellReuseIdentifier:@"cell2"];
    
    [self.myTableView registerClass:[HomeCTableViewCell class] forCellReuseIdentifier:@"cellC"];
    
    
}



- (void)searchButtonAction:(UIBarButtonItem *)button{
    NSLog(@"🀄️🀄️🀄️搜索按钮");
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSInteger i = indexPath.row % 3;
    if (i == 0 ) {
        return 220;
    }
    if (i == 1) {
        return 240;
    }
    if (i == 2) {
        return 550;
    }
    
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    // 判断
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSInteger i = indexPath.row % 3;
    
    if (i == 0) {
        HomeTableViewCell *cellC = [tableView dequeueReusableCellWithIdentifier:@"cellCollect"];
        return cellC;
    }
    if (i == 1) {
        HomeABTableViewCell *cellAB = [tableView dequeueReusableCellWithIdentifier:@"cell2"];
        return cellAB;
    }
    if (i == 2) {
        HomeCTableViewCell *cellCC = [tableView dequeueReusableCellWithIdentifier:@"cellC"];
        return cellCC;
    }
    return 0;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
